﻿#pragma once
#include "MeshMaterial.h"

class FInstanceMeshMaterial final
	: public FMeshMaterialBase
{
public:
	[[nodiscard]] std::filesystem::path GetVsSrcPath() const override
	{
		return FPath::BuildShaderPath("Mesh/shaderInstance.vs");
	}

	[[nodiscard]] std::filesystem::path GetFsSrcPath() const override
	{
		return FPath::BuildShaderPath("Mesh/shaderInstance.fs");
	}

private:

	std::vector<std::shared_ptr<FTexture2D>> TextureArray;

public:

	virtual bool Init() override
	{
		InitShaderWayType = EInitShaderWayType::File;

		if (!FMaterial::Init())
		{
			return false;
		}

		Shader->SetLightingModel(ELightingModel::Diffuse);

		for (const auto& TextureInfo : TextureInfos)
		{
			FTextureBuild Build;
			const auto Texture = Build.Build(TextureInfo.TexturePath);
			TextureArray.push_back(Texture);
		} 

		Shader->Use();

		Shader->SetInt("texture_diffuse1", 0);

		return true;
	}

	virtual void Use() override
	{
		FMaterial::Use();

		if (!TextureArray.empty())
		{
			TextureArray[0]->BindTextureUnit(0);
		}
	}
};
